package com.ossean.match.matchprocess;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.ossean.match.dao.ProjectDao;
import com.ossean.match.dao.RelativeMemoDao;
import com.ossean.match.dao.TagDao;

@Component("newprjmonitor")
public class NewPrjMonitor {

	@Resource
	private TagDao tagDao;
	@Resource
	private ProjectDao projectDao;
	@Resource
	private RelativeMemoDao memoDao;

	MatchIncrement matchIncrement = null;

	public void setMatchIncrement(MatchIncrement matchIncrement) {
		this.matchIncrement = matchIncrement;
	}

	public void run() {
		int lastPrjId = projectDao.getNewLast();
		int lastMemoId = memoDao.getLastMemoId();
		int lastTagId = tagDao.getNewLast();
		int lastPrePrjId = lastPrjId;
		if (lastPrjId > matchIncrement.getPrjHistory()) {
			matchIncrement.setNewPrjComming(true);
			matchIncrement.setLastPrjId(lastPrjId);
			
		} else {
			matchIncrement.setNewPrjComming(false);
		}
		if (lastMemoId > matchIncrement.getMemoHistory()) {
			matchIncrement.setNewMemoComming(true);
		} else {
			matchIncrement.setNewMemoComming(false);
		}
		
		if (lastPrePrjId > matchIncrement.getPrePrjHistory()) {
			matchIncrement.setNewPrePrjFlag(true);
			matchIncrement.setLastPrePrjId(lastPrePrjId);
		} else {
			matchIncrement.setNewPrePrjFlag(false);
		}
		
		if (lastTagId > matchIncrement.getTagHistory()) {
			matchIncrement.setNewTagflag(true);
			matchIncrement.setLastTagId(lastTagId);
			
		} else {
			matchIncrement.setNewTagflag(false);
		}
		if (!matchIncrement.isNewMemoComming()&&!matchIncrement.isNewPrjComming()) {
			matchIncrement.setSleepTime(120000);
		}else {
			matchIncrement.setSleepTime(0);
		}
	}
	
}
